<?

require dirname(__FILE__) . '/lib/tagcloud.php';
$text = implode(' ', $_POST['names']);
$font = dirname(__FILE__) . '/lib/Arial.ttf';

$width = 607;
$height = 500;
$cloud = new WordCloud($width, $height, $font, $text);
$palette = Palette::get_palette_from_hex($cloud->get_image(), array('FFA700', 'FFDF00', 'FF4F00', 'FFEE73'));
$cloud->render($palette);

$img = microtime(true) . rand(1000, 9999) . '.png';
$file = dirname(__FILE__) . '/images/' . $img;
imagepng($cloud->get_image(), $file);

echo json_encode($img);